<template>
  <div class='list'>
    <header>
      <div class='returns'>
        <i class='iconfont icon-fanhui'></i>
      </div>
      <div class='search'>
        <i class='iconfont icon-fangdajing'></i>
        <span>搜您喜欢的...</span>
      </div>
      <div class='go-home'>
        <img
          src="@/assets/images/home.png"
          alt=""
        >
      </div>
    </header>
    <section>
      <!-- <div class='list-l'>
        <ul class='l-item'>
          <li class='active'>推荐</li>
          <li>推荐</li>
          <li>推荐</li>
          <li>推荐</li>
          <li>推荐</li>
        </ul>
      </div> -->
      <div class='list-l'>
        <ul class='l-item'>
          <li
            v-for='(item,index) in leftData'
            :key='index'
            class='active'
          >{{item.name}}</li>
        </ul>
      </div>

      <!-- <div class='list-r'>
        <ul>
          <li class='shop-list'>
            <h2>推荐</h2>
            <ul class='r-content'>
              <li>
                <img
                  src="@/assets/images/list1.jpeg"
                  alt=""
                >
                <span>铁观音</span>
              </li>
              <li>
                <img
                  src="@/assets/images/list1.jpeg"
                  alt=""
                >
                <span>铁观音</span>
              </li>
              <li>
                <img
                  src="@/assets/images/list1.jpeg"
                  alt=""
                >
                <span>铁观音</span>
              </li>
              <li>
                <img
                  src="@/assets/images/list1.jpeg"
                  alt=""
                >
                <span>铁观音</span>
              </li>
              <li>
                <img
                  src="@/assets/images/list1.jpeg"
                  alt=""
                >
                <span>铁观音</span>
              </li>
            </ul>
          </li>
        </ul>
      </div> -->
      <div class='list-r'>
        <ul
          v-for='(item,index) in rightData'
          :key='index'
          class='shop-list'
        >
          <!-- {{rightData}}  -->
          <li
            v-for="(k,i) in item"
            :key='i'
          >
            <h2>{{k.name}}</h2>
            <ul class='r-content'>
              <li
                v-for='(j,idx) in k.list'
                :key='idx'
                @click="goDetail(1)"
              >
                <img
                  :src="j.imgUrl"
                  alt=""
                >
                <span>{{j.name}}</span>
              </li>
            </ul>
          </li>
        </ul>
      </div>
    </section>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import Tabbar from "@/components/common/Tabbar.vue";
import BScroll from "@better-scroll/core";
import Indicator from "../common/api/request.js";
export default {
  name: "List",
  data() {
    return {
      leftData: [], //左侧数据
      rightData: [], //右侧数据
    };
  },
  methods: {
    goDetail(id) {
      this.$router.push({
        path: "/detail" /*显式传递*/,
        query: {
          id /* id: id,  显式传递*/,
        }, //下面隐式传递
        //name: "Detail",
        //params: {
        //  id: id,
        //},
      });
    },
  },
  components: {
    Tabbar,
  },
  async created() {
    let res = await Indicator.$axios({
      url: "/api/goods/list", //图片地址放在public里面
    });
    console.log(res);

    let leftArr = []; //获取左侧的名字做循环
    let rightArr = []; //获取右侧的数据做循环

    res.forEach((v) => {
      //一个循环为左边和右边赋值
      leftArr.push({
        id: v.id,
        name: v.name,
      });
      //console.log(v); //大类 推荐/xx的数组
      //console.log(v.data);//小类
      rightArr.push(v.data); //右侧的是小类  给右侧赋值
    });
    this.leftData = leftArr;
    this.rightData = rightArr;
  },
};
</script>
<style scoped lang='scss'>
.list {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 1.4667rem;
  background-color: #b0352f;
  .returns {
    line-height: 1.4667rem;
    padding: 0 0.533333rem;
    i {
      color: #fff;
      font-size: 0.693333rem;
    }
  }
  .search {
    display: flex;
    align-items: center;
    flex: 1;
    padding: 0.16rem 0.266666rem;
    background-color: #ffffff;
    border-radius: 0.64rem;
    i {
      padding-right: 0.1067rem;
      color: #666;
      font-size: 0.6133rem;
    }
    span {
      color: #666;
      font-size: 0.373333rem;
    }
  }
  .go-home {
    padding: 0 0.266666rem;
    line-height: 1.173333rem;
    img {
      display: flex;
      width: 1.04rem;
      height: 1.04rem;
    }
  }
}
section {
  display: flex;
  flex: 1;
  overflow: hidden;
}
/* 左边栏 */
.list-l {
  width: 2.48rem;
  background-color: #fff;
  border-right: 1px solid #cccccc;
  overflow: hidden;
  .l-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    li {
      width: 100%;
      /* line-height: 1.333333rem; */
      padding: 0.1867rem 0px;
      margin: 0.4rem 0;
      text-align: center;
      font-size: 0.373333rem;
      &.active {
        //li里面.active的class属性
        /* 新语法 */
        color: #b54f4a;
        border-left: 6px solid #b54f4a;
      }
    }
  }
}
/* 右边栏 */
.list-r {
  flex: 1;
  overflow: hidden;
  .shop-list {
    text-align: center;
    h2 {
      padding: 0.533333rem 0;
      font-size: 0.64rem;
      font-weight: 400;
    }
    .r-content {
      display: flex;
      flex-wrap: wrap;
      li {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 33.33%;
        padding: 0.266666rem 0;
        img {
          width: 1.413333rem;
          height: 1.413333rem;
        }
        span {
          font-size: 0.426666rem;
        }
      }
    }
  }
}
::v-deep.tabbar {
  border-top: 1px solid #cccccc;
}
</style>


